
#define IO_DEMO 0 // Change to 0 to enable 'real' main function.

#if IO_DEMO

#include <iostream>
#include <algorithm>

#include "Core.h"
#include "RecordManager.h"

#include "FlightRecord.h"
#include "CustomerRecord.h"
#include "BookingRecord.h"
#include "UserRecord.h"

#include "TimeDate.h"

using namespace AirlineRes;

int main()
{
  // Create a record manager object and load data from disk.
  RecordManager<UserRecord> userRecordManager;
  userRecordManager.LoadRecords( "users.txt" );

  // Get a pointer to the record set.
  auto users = userRecordManager.GetRecordSet();

  // Add some records.
  UserRecord ur1( "Herbert", "HerbertIsCool", true );
  UserRecord ur2( "Bartholomew", "EatMyShorts", false );
  userRecordManager.AddRecord( ur1 );
  userRecordManager.AddRecord( ur2 );

  // Edit a record.
  auto tmpRecord = *std::find_if(
    users->begin(), users->end(),
    [](UserRecord const& _a){ return _a.GetUsername() == "Herbert"; }
  );

  tmpRecord.SetPassword( "HerbertIsNotCool" );
  userRecordManager.EditRecord( tmpRecord );

  // Edit a record in a different way.
  for ( auto it = users->begin(); it != users->end(); ++it )
  {
    if ( it->GetUsername() == "Bartholomew" )
    {
      auto tmpRecord = *it;
      tmpRecord.SetPassword( "IronMyShorts" );
      userRecordManager.EditRecord( tmpRecord );
      break;
    }
  }

  // Print records to screen via the pointer we got earlier.
  for ( auto it = users->begin(); it != users->end(); ++it )
  {
    it->WriteRecord( std::cout );
  }

  // Save to disk.
  userRecordManager.WriteRecords( "test_output_users.txt" );

  // Test the TimeDate class
  std::cout << "Time test\n";
  TimeDate t( 1999, 1, 2 );
  std::cout << t.GetISODate() << " " << t.GetHHMM() << "\n";

  std::cout << "Done. Press ENTER to exit.\n";
  std::cin.ignore(1);

  return 0;
}

#else

#include <iostream>
#include "AirlineReservationSystem.h"

using namespace AirlineRes;

int main()
{
  AirlineReservationSystem arSystem;

  arSystem.Init();
  arSystem.Run();
  arSystem.Shutdown();

  std::cout << "\nDone. Press ENTER to exit.\n";
  std::cin.sync();
  std::cin.get();

  return 0;
}

#endif